/*
	klib_PCIE.h

	contains headers for PCIE control/access functions

	Author: Aidan Goddard 26/1/14
*/

#ifndef KLIB_PCIE_H_INCLUDED
#define KLIB_PCIE_H_INCLUDED

uint32_t	__KLIB__PCIEGetDeviceCount(uint32_t *device_count);
uint32_t 	__KLIB__PCIEGetDevices(HANDLE *handles);

uint32_t 	__KLIB__PCIEGetDeviceCountOfClass(uint32_t *device_count, uint32_t main_class);
uint32_t 	__KLIB__PCIEGetDevicesOfClass(HANDLE *handles, uint32_t main_class);

uint32_t 	__KLIB__PCIEGetDeviceAddress(HANDLE handle, uint32_t *bus, uint32_t *device, uint32_t *function, uint32_t *IRQ_PIN);
uint32_t 	__KLIB__PCIEGetDeviceIDs(HANDLE handle, uint32_t *class_code, uint32_t *vendor_ID, uint32_t *device_ID);

uint32_t	__KLIB__PCIEReserveDevice(HANDLE handle, uint64_t *key);
uint32_t	__KLIB__PCIEFreeDevice(HANDLE handle, uint64_t key);

uint32_t 	__KLIB__PCIEConfigRead(HANDLE handle, uint64_t key, uint32_t dword_offset, uint32_t *buffer);
uint32_t 	__KLIB__PCIEConfigWrite(HANDLE handle, uint64_t key, uint32_t dword_offset, uint32_t buffer);


#define PCIE_SUCCESS				0
#define PCIE_NO_DEVICES				0xffffffff
#define PCIE_INVALID_HANDLE			0xfffffffe
#define PCIE_INVALID_KEY			0xfffffffd
#define PCIE_DEVICE_NOT_AVAILABLE	0xfffffffc
#define PCIE_DEVICE_OWNED_BY_SYSTEM	0xfffffffb
#define PCIE_INVALID_DWORD_OFFSET	0xfffffffa
#define PCIE_DEVICE_NOT_RESERVED	0xfffffff9


#define PCIE_IRQ_NO_PIN			0
#define PCIE_IRQ_PIN_A			1
#define PCIE_IRQ_PIN_C			2
#define PCIE_IRQ_PIN_B			3
#define PCIE_IRQ_PIN_D			4


#endif
